package com.jiuzhi.app.common.util;

/**
 * Created by moloch on 2017/9/6.
 * @author zm
 */
public class ResultInfo<T> {

    public static final Integer OK = 1;

    public static final Integer ERROR = 0;

    public static final Integer ERROR_PARAM = 2;

    private Integer status;

    private String msg;

    private T result;

    public String getMsg() {
        return msg;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static <T> ResultInfo<T> newInstance() {
        return new ResultInfo<>();
    }


    /**
     * @param c
     * @param data
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResultInfo<T> genResultInfo(Integer c,T data,String message){
        ResultInfo<T> result = ResultInfo.newInstance();
        result.setStatus(c);
        result.setMsg(message);
        result.setResult(data);
        return result;
    }

    /**
     * 成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResultInfo<T> genOkResultInfo(T data){
        return genResultInfo(OK,data,"");
    }

    /**
     * 失败
     * @param <T>
     * @return
     */
    public static <T> ResultInfo<String> genErrorResultInfo(Integer status ,String message){
        return genResultInfo(status,"",message);
    }


    public static Integer getIsOK() {
        return OK;
    }

    public static Integer getIsError(){
        return ERROR;
    }

    public static Integer getErrorParam() {
        return ERROR_PARAM;
    }

}
